﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Routing;

namespace SVN.Net
{
    public class GlobalApplication : System.Web.HttpApplication
    {
        public static void RegisterRoutes(RouteCollection routes)
        {
            routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

            routes.MapRoute(
                "Default",                                              // Route name
                "{controller}/{action}/{id}",                           // URL with parameters
                new { controller = "Home", action = "Index", id = "" }  // Parameter defaults
            );

        }

        protected void Application_Start()
        {
            RegisterRoutes(RouteTable.Routes);
        }

        public static string GetPath(string path)
        {
            var ret = path;
            var pos = path.LastIndexOf('/');
            if (pos >= 0)
                ret = path.Substring(0, path.LastIndexOf('/'));
            return ret;
        }

        public static string GetName(string path)
        {
            var ret = path;
            var pos = path.LastIndexOf('/');
            if (pos >= 0)
                ret = path.Substring(path.LastIndexOf('/') + 1);
            return ret;
        }

        public static string Combine(string path, string name)
        {
            return string.Format("{0}/{1}", path, name);
        }
    }
}